Prev | Current Page 176 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"

department_id)}
{assign var=selected value="class=\"selected\""}
{/if}

  • {* Generate a link for a new department in the list *}

    {$obj->mDepartments[i].name}


  • {/section}


    {* End departments list *}
    4. Create a folder named smarty_plugins in the presentation folder. This will contain the Smarty
    plug-in files.
    5. Inside the smarty_plugins folder, create a file named function.load_presentation_object.php,
    and add the following code to it:
    // Plug-in functions inside plug-in files must be named: smarty_type_name
    function smarty_function_load_presentation_object($params, $smarty)
    {
    require_once PRESENTATION_DIR . $params['filename'] . '.php';
    $className = str_replace(' ', '',
    ucfirst(str_replace('_', ' ',
    $params['filename'])));
    // Create presentation object
    $obj = new $className();
    if (method_exists($obj, 'init'))
    {
    $obj->init();
    }
    // Assign template variable
    $smarty->assign($params['assign'], $obj);
    }
    ?>
    6. Inside the presentation folder, create a file named departments_list.php, and add the following
    code to it:
    // Manages the departments list
    class DepartmentsList
    {
    CHAPTER 4 ?–  CREATING THE PRODUCT CATALOG: PART 1 103
    /* Public variables available in departments_list.tpl Smarty template */
    public $mSelectedDepartment = 0;
    public $mDepartments;
    // Constructor reads query string parameter
    public function __construct()
    {
    /* If DepartmentId exists in the query string, we're visiting a
    department */
    if (isset ($_GET['DepartmentId']))
    $this->mSelectedDepartment = (int)$_GET['DepartmentId'];
    }
    /* Calls business tier method to read departments list and create
    their links */
    public function init()
    {
    // Get the list of departments from the business tier
    $this->mDepartments = Catalog::GetDepartments();
    // Create the department links
    for ($i = 0; $i < count($this->mDepartments); $i++)
    $this->mDepartments[$i]['link_to_department'] =
    'index.


    Pages:
    164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
    śmieszne dowcipy dieta light życzenia ślubne portal Connie Talbot